﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NCmd;
using UnityEngine.SceneManagement;
using UnityEngine;

// 选人界面管理器
public class SelectRoleMgr : Singleton<SelectRoleMgr>
{
    // 保存从服务器消息中传过来的角色列表
    List<RoleSelect> _allRoleList = new List<RoleSelect>();

    GameObject _selectRoleUIRoot;

    // 获取当前角色列表
    internal List<RoleSelect> GetAllRoleList()
    {
        return _allRoleList;
    }

    // 响应服务器发过来的RoleList消息
    public static void OnRoleList(Cmd cmd)
    {
        RoleList roleList = cmd as RoleList;

        // 服务器的数据保存到本地
        SelectRoleMgr.Instance._allRoleList = roleList.AllRoleList;

        if (roleList.AllRoleList.Count <= 0)
        {
            // 显示创建角色界面
        }
        else
        {
            // 选择选人界面
            //SceneManager.LoadScene("Scenes/SelectRole");
            SelectRoleMgr.Instance._selectRoleUIRoot = UIManager.Instance.ReplaceUI("Prefabs/UI/SelectRole/SelectRole");
        }
    }

    // 删除选人界面UI
    internal void OnLoadScene()
    {
        if (_selectRoleUIRoot != null)
        {
            UIManager.Instance.Release(_selectRoleUIRoot);
        }
    }
}
